package com.sto.stoapp.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.entity.RouteEntity;

/**
 * 业务设置-路由表-Adapter
 * 
 * @author mgf
 * 
 */
public class RouteListAdapter extends BaseAdapter {

	private List<RouteEntity> mLists;
	private Context mContext;

	public RouteListAdapter(Context context, List<RouteEntity> lists) {
		mContext = context;
		mLists = lists;
	}

	@Override
	public int getCount() {
		return mLists == null ? 0 : mLists.size();
	}

	@Override
	public Object getItem(int position) {
		return mLists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Holder holder;
		if (convertView == null) {
			holder = new Holder();
			convertView = LayoutInflater.from(mContext).inflate(
					R.layout.route_adapter_item, null);
			holder.routeCodeView = (TextView) convertView
					.findViewById(R.id.route_code);
			holder.nextStationView = (TextView) convertView
					.findViewById(R.id.route_next_station);
			holder.centerDesView = (TextView) convertView.findViewById(R.id.route_center_des);
			convertView.setTag(holder);
		} else {
			holder = (Holder) convertView.getTag();
		}
		holder.routeCodeView.setText(mLists.get(position).getRouteCode());
		holder.nextStationView.setText(mLists.get(position).getNextStation());
		holder.centerDesView.setText(mLists.get(position).getCenterDes());
		return convertView;
	}

	class Holder {
		TextView routeCodeView;
		TextView nextStationView;
		TextView centerDesView;
	}

}
